#include<iostream>
#include<malloc.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

char Preorder[50],Inorder[50];
typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;

//树节点的定义
struct TNode
{
    ElementType Data;//节点数据
    BinTree Left;//指向左子树
    BinTree Right;//指向右子树
};

BinTree build_tree(int pre_root,int in_start,int end);
int get_height(BinTree T);

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>Preorder[i];
    for(int i=0;i<n;i++)
        cin>>Inorder[i];
    cout<<get_height(build_tree(0,0,n-1));
}

BinTree build_tree(int pre_root,int in_start,int end)
{
    if(in_start>end) return NULL;
    int i;

    for(i=in_start;i<=end;i++)
        if(Inorder[i]==Preorder[pre_root]) break;

    BinTree T;
    T=(BinTree)malloc(sizeof(struct TNode));
    T->Data=Preorder[pre_root];
    T->Left=build_tree(pre_root+1,in_start,i-1);
    T->Right=build_tree(pre_root+1+i-in_start,i+1,end);
    return T;
}
int get_height(BinTree T)
{
    if(!T) return 0;
    else
    {
        int left=get_height(T->Left);
        int right=get_height(T->Right);
        int height=left>right?left:right;
        return height+1; 
    }
}

